/*->c.vxdef */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <time.h>

#include "h.os"
#include "h.wimp"



#include "h.wos"
#include "h.main"
#include "h.ram"
#include "h.mym"
#include "h.main"
#include "h.key"


#include "h.serial"

#include "h.term"

#include "h.vxdef"

#include "h.vxwimp"
#include "h.vxterm"




/***************************************************************************/
/*
 Code to handle Viewdata terminals global variables
*/
/***************************************************************************/

int vxopen;                        /* Viewdata terminal window open */
int vxexists;

int viewescflag;                   /* Escape flag */
int vxhash;                        /* hash flag */
int vedit;                         /* Editor mode */


int ttvx;                          /* cursor posn */
int ttvy;

int mttvx;                         /* mouse coords */
int mttvy;


int vxmovecurs;
int vxcurs;
int vxblock;                       /* block cursor */
int vxcursphase;
int vxmodded;
int vxpendredraw;
int vxcurstime;
int vxauto;                        /* auto repeat */
int vxbeep;

int vxflashtime;
int vxflashphase=VXFLASH2;

vxscreen * vscr;


int vxkeypad;                   /* flag, is there a keypad or not */

int  vxshortlines;               /* short lines in frame send */
int  vxechocheck;                /* echo check                */
int  vxdump;                     /* dump type TEXT/GR+/GR-    */
int  vxprintff;                  /* printer form feed         */
int  vxslotel;                   /* slo telesoftware          */
int  vxcetel;                    /* CET protocol              */
char vxceteol[32];
char vxanswerbackstring[32];
char vxmbxreply[32];
char vxprefix[32];
char vxsuffix[32];
char vxaseq[32];
char vxatseq[32];
char vxsolseq[32];
char vxechopacestring[32];



int  vxautoresume;               /* Auto resume dloads        */
int  vxreturnishash;             /* RETURN is hash            */
int  campusreturnishash;
int  campusdefault=TERMVX;
int  vxescseq;                  /* use escape sequences      */
int  vxechopace;                /* pace for sending chars with no echo check */

int vxlocal;                    /* local mode */
int vxlocalecho;                /* local echo */

int vxtxcrlnf;                  /* send CRLF ?    */
int vxrxcrlnf;                  /* receive CRLF ? */
int vxbit8c;                    /* allow 8 bits   */

int vxinvert;                   /* B<->W */

int vxhearsayff;                /* use Hearsay frame files ? */
int vxframesize;                /* default frame size */
                                /* logic is if minitel then CEPT 2 */
                                /* else hearsay or arcomm */


zoomer            vxdefz={1,1,1};
zoomer            vxbdefz={4,5,1};

int               vxdeftools;


/*****************************************************************************/
/* channels */


/* viewx(int byte) is the fundamental input to the viewdata terminal */



/* allows input of all codes direct to terminal */

void viewhi(int i)
{
 if(i>127 && i<160)
 {
  viewx(27);
  viewx(i-64);
 }
 else                              
 if(i>159) viewx(i-128);
 else
 viewx(i);
}





void viewlinelo(int i)
{
 if(vxlocal)
 {
  savetmode(TMODEVX);
  tty(i);
  loadtmode();
 }
 else
 {
  if(vxlocalecho) tty(i);
  termoutbyte(i);
 }
}





/* used to send bytes to line by viewdata terminal */
/* return 0 on OK */

int viewline(int i)
{
 if(i>128 && i<160)
 {
  viewlinelo(27);
  viewlinelo(i-64);
 }
 else
 if(i>159) viewlinelo(i-128);
 else      viewlinelo(i);

 return(0);
}




void viewstringline(char * string)
{
 int len=strlen(string);
 int i;
 for(i=0;i<len;i++) if(viewline(string[i])) break;
}




/* take a | string, convert to codes and send them return 1 on failure */

int viewconvertstringline(char * string)
{
 return(expandmacro(viewline,string));
}



/* used to send key codes to line */

void viewkeyline(int i)
{
 viewline(i);
}




